<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>倒计时</title>
    <style>
        .box {
            width: 300px;
            padding: 10px;
            background-color: #369;
            font-family: "Microsoft YaHei UI Light";
            font-weight: 500;
            margin: 100px auto;
            overflow: hidden;
            border-radius: 5px;
        }

        .box p {
            color: white;
        }

        .box div{
            float: right;
        }

        s{
            text-decoration: none;
            font-size: 30px;
            color: #aaa;
        }

        .box span{
            font-size: 18px;
            color: white;
        }
    </style>
    <script>
        window.onload = function () {
            var oldDate = new Date(2015,04,17,0,0,0);
            console.log(oldDate.toLocaleString());
            var day = document.getElementById("day");
            var hour = document.getElementById("hour");
            var min = document.getElementById("min");
            var second = document.getElementById("second");
            Countdown();
            setInterval(Countdown,1000);

            function Countdown() {
                var difftime = new Date().getTime() - oldDate.getTime();
                var passDay = parseInt(difftime/(1000*60*60*24));
                var passHour = parseInt((difftime - passDay*24*60*60*1000)/(1000*60*60));
                day.innerText = zero(passDay);
                hour.innerText = zero(passHour);
                min.innerText = zero(new Date(difftime).getMinutes());
                second.innerText = zero(new Date(difftime).getSeconds());
            }
        }

        function zero(num) {
            return num<10 ? "0"+num : num;
        }
    </script>
</head>
<body>
<div class="box">
    <p>距离2015年5月17日</p>
    <div>
        <span id="day">22</span>
        <s>天</s>
        <span id="hour">22</span>
        <s>时</s>
        <span id="min">22</span>
        <s>分</s>
        <span id="second">22</span>
        <s>秒</s>
    </div>
</div>
</body>
</html>